''' Mission 14 - Line Art Objective 9 ''' from codex import * # Grid spacing (pixels) GRID = 10 # Variables for screen center x_center = int(display.width / 2) y_center = int(display.height / 2) # Draw a grid of white pixels for y in range(0, display.height, GRID): for x in range(0, display.width, GRID): display.set_pixel(x, y, WHITE) # Horizontal and vertical lines display.draw_line(0, y_center, display.width, y_center, RED) display.draw_line(x_center, 0, x_center, display.height, RED) # Blue border display.draw_rect(0, 0, display.width, display.height, BLUE) def draw_web(x1, y1, x2, y2, count, color): # Calculate the step size "deltas" for x and y dx1 = int((x2 - x1) / count) dy1 = int((y2 - y1) / count) dx2 = dy1 dy2 = -dx1 # Draw the line and move endpoints by dx, dy for i in range(count): display.draw_line(x1, y1, x2, y2, color) x1 = x1 + dx1 y1 = y1 + dy1 x2 = x2 + dx2 y2 = y2 + dy2 # String art! WEB_SPACING = 20 # outside webs draw_web(0, 0, 0, 239, WEB_SPACING, GREEN) draw_web(0, 239, 239, 239, WEB_SPACING, YELLOW) draw_web(239, 239, 239, 0, WEB_SPACING, CYAN) draw_web(239, 0, 0, 0, WEB_SPACING, MAGENTA) # inside webs draw_web(120, 0, 120, 120, WEB_SPACING, ORANGE) draw_web(0, 120, 120, 120, WEB_SPACING, RED) draw_web(120, 239, 120, 120, WEB_SPACING, WHITE) draw_web(239, 120, 120, 120, WEB_SPACING, PINK)